<template>
  <div class="login_main">
    <div class="head_con_background"></div>
    <div class="login_container">
      <div class="head_con">
        <p class="blog_font">CemCode | Blog 后台</p>
      </div>
      <el-form @submit.native.prevent class="btn_content">
        <div class="input_con">
          <p class="input_label">用户名:</p>
          <input type="text" placeholder="请输入用户名" v-model="userName" />
        </div>
        <div class="input_con">
          <p class="input_label">密码:</p>
          <input type="password" autocomplete placeholder="请输入密码" v-model="password" />
        </div>
        <div class="input_con">
          <button @click="login" class="btn_login">登录</button>
        </div>
      </el-form>
    </div>
  </div>
</template>
<script>
import { Message } from "element-ui";

export default {
  name: "admin-login",
  data() {
    return {
      userName: "",
      password: "",
    };
  },
  methods: {
    // 登录
    login() {
      const name_rule = /^\w{1,10}$/;
      const pwd_rule = /^\w{1,16}$/;

      if (this.userName === "" && !name_rule.test(this.userName)) {
        // 用户名规则错误
        Message.error("用户名格式错误");
      } else if (this.password === "" && !pwd_rule.test(this.password)) {
        Message.error("用户密码格式错误");
      } else {
        let parmas = {
          admin_name: this.userName,
          admin_pwd: this.password,
        };
        this.$store.dispatch("LoginAction", parmas).then((result) => {
          console.log(result);
          Message.success(result.msg);
          this.$router.push("/admin");
        });
      }
    },
  },
};
</script>
<style lang="scss" scoped>
$primary-color: #00a9ff;
$primary-font-color: white;
$title-font-color: #333;
$message-font-color: #333;
$thin-font-color: #999;

.login_main {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;

  .head_con_background {
    width: 300px;
    height: 300px;
    border-radius: 0%;
    background-color: gray;
    box-shadow: 0 0 1000px 15px #c5c5c5;
    position: absolute;
    z-index: 1;
  }

  .login_container {
    width: 350px;
    height: 400px;
    position: relative;
    border-radius: 7px;
    overflow: hidden;
    z-index: 2;
    background-color: white;
    // box-shadow: 0px -5px 15px 0 rgb(223, 223, 223);
    .head_con {
      width: 100%;
      height: 60px;
      text-align: center;
      line-height: 60px;
      color: $primary-font-color;
      background-image: linear-gradient(
        to bottom left,
        #03a2f1,
        #00a9ff,
        #108cff
      );
      .blog_font {
        font-size: 16px;
        font-weight: bold;
      }
    }

    .btn_content {
      width: 100%;
      height: calc(100% - 50px);
      box-sizing: border-box;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;

      .input_con {
        width: 75%;
        .input_label {
          font-size: 14px;
          color: gray;
          margin-bottom: 10px;
        }

        input {
          height: 40px;
          width: 100%;
          outline: none;
          box-sizing: border-box;
          padding-left: 5px;
          border-radius: 3px;
          border: 1px solid rgb(218, 218, 218);
          color: $message-font-color;
          margin-bottom: 20px;
        }
      }

      .btn_login {
        width: 100%;
        height: 40px;
        margin-top: 20px;
        background-image: linear-gradient(
          to top right,
          #00a3f5,
          #00a9ff,
          #1e92ff
        );
        color: $primary-font-color;
        border: 0;
        border-radius: 5px;
        transition: 0.5s;
      }

      .btn_login:hover {
        cursor: pointer;
        transition: 0.5s;
        box-shadow: 0 0 15px 0 #9aceff;
        background-image: linear-gradient(
          to top right,
          #009ae7,
          #0baeff,
          #0787ff
        );
      }
    }
  }
}
</style>